package cn.stylefeng.guns.modular.system.controller;

import cn.stylefeng.guns.base.pojo.page.LayuiPageFactory;
import cn.stylefeng.guns.base.pojo.page.LayuiPageInfo;
import cn.stylefeng.guns.base.shiro.annotion.Permission;
import cn.stylefeng.guns.modular.system.entity.SalesOrder;
import cn.stylefeng.guns.modular.system.entity.SalsOrderCheck;
import cn.stylefeng.guns.modular.system.model.params.SalesOrderParam;
import cn.stylefeng.guns.modular.system.model.params.paramsDTO.SaleOrderDTO;
import cn.stylefeng.guns.modular.system.service.Myservice.SalesOrService;
import cn.stylefeng.guns.modular.system.service.SalesOrderService;
import cn.stylefeng.guns.modular.system.service.SalsOrderCheckService;
import cn.stylefeng.guns.sys.core.shiro.ShiroKit;
import cn.stylefeng.guns.sys.core.util.utility.StatusCode;
import cn.stylefeng.guns.sys.modular.system.service.DeptService;
import cn.stylefeng.roses.core.base.controller.BaseController;
import cn.stylefeng.roses.core.reqres.response.ResponseData;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.apache.xmlbeans.impl.regex.REUtil;
import org.beetl.ext.simulate.BaseSimulate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.List;


/**
 * 销售订单控制器
 *
 * @author 小飞
 * @Date 2019-07-04 10:19:10
 */
@Controller
@RequestMapping("/salesOrder")
public class SalesOrderController extends BaseController {

    private String PREFIX = "/salesOrder";

    @Autowired
    private SalesOrderService salesOrderService;
    @Autowired
    private SalesOrService salesOrService;
    @Autowired
    private DeptService deptService;
    /**
     * 跳转到主页面
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @RequestMapping("")
    public String index() {
        return PREFIX + "/salesOrder.html";
    }

    /**
     * 新增页面
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @RequestMapping("/add")
    public String add() {
        super.setAttr("name",ShiroKit.getUserNotNull().getName());
        super.setAttr("dept",deptService.getById(ShiroKit.getUserNotNull().getDeptId()).getSimpleName());
        return PREFIX + "/salesOrder_add.html";
    }

    /**
     * 编辑页面
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @RequestMapping("/edit")
    public String edit() {
        return PREFIX + "/salesOrder_edit.html";
    }

    /**
     * 无特价申请新增接口
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @RequestMapping("/addItem")
    @ResponseBody
    public ResponseData addItem(SalesOrderParam salesOrderParam) {
       // salesOrService.commonAddItem(salesOrderParam.getPurchaseOrder(), salesOrderParam.getSaleOrderDto());
        return ResponseData.success();
    }

    /**
     * 特价申请新增接口
     *
     * @param salesOrderParam
     * @return
     */
    @RequestMapping("/addSpecialItem")
    @ResponseBody
    public ResponseData addSpecialItem(SalesOrderParam salesOrderParam,SaleOrderDTO saleOrderDTO) {
        salesOrService.specialAddItem(salesOrderParam.getPurchaseOrder(), saleOrderDTO);
        return ResponseData.success();
    }

    /**
     * 编辑接口
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @RequestMapping("/editItem")
    @ResponseBody
    public ResponseData editItem(SalesOrderParam salesOrderParam) {
        this.salesOrderService.update(salesOrderParam);
        return ResponseData.success();
    }

    /**
     * 删除接口
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @RequestMapping("/delete")
    @ResponseBody
    public ResponseData delete(SalesOrderParam salesOrderParam) {
        this.salesOrderService.delete(salesOrderParam);
        return ResponseData.success();
    }

    /**
     * 查看详情接口
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @RequestMapping("/detail")
    @ResponseBody
    public ResponseData detail(SalesOrderParam salesOrderParam) {
        SalesOrder detail = this.salesOrderService.getById(salesOrderParam.getId());

        return ResponseData.success(detail);
    }

    /**
     * 查询列表
     *
     * @author 小飞
     * @Date 2019-07-04
     */
    @ResponseBody
    @RequestMapping("/list")
    public LayuiPageInfo list(SalesOrderParam salesOrderParam) {

        Long userId = ShiroKit.getUserNotNull().getId();
        return salesOrderService.findPageBySpec(salesOrderParam, userId);
    }



    /*--------------------提交审核接口----------------------------------------------*/


    /**
     * 普通状态下提交
     * @param purchaseOrder
     * @param saleOrderDto
     * @return
     */
    @RequestMapping("/submitCommon")
    public ResponseData submitCommon(String purchaseOrder, SaleOrderDTO saleOrderDto){
        salesOrService.commonAddItem(purchaseOrder,saleOrderDto);
        return  ResponseData.success();
    }

    /**
     * 特价状态提交
     * @param purchaseOrder
     * @param saleOrderDto
     * @return
     */
    @RequestMapping("/specialAddItem")
    public ResponseData specialAddItem(String purchaseOrder,SaleOrderDTO saleOrderDto){
        salesOrService.specialAddItem(purchaseOrder,saleOrderDto);
        return  ResponseData.success();
    }
}
